package com.colorlight.cloud.complete.entity.event;

import com.colorlight.cloud.complete.api.CompleteEntityEvent;
import com.colorlight.cloud.complete.entity.enumerate.UploadResult;
import com.colorlight.iot.proto.complete.event.CompleteEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 屏幕截图上报事件
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class UploadScreenshotReport implements CompleteEntityEvent {

    /**
     * 上报路径
     */
    private String url;

    /**
     * 上传后的结果上报
     */
    private UploadResult uploadResult;

    @Override
    public UploadScreenshotReport byteConvertObject(ByteString bytes) {
        CompleteEvent.UploadScreenshotReport uploadScreenshotReport = null;
        try {
            uploadScreenshotReport = CompleteEvent.UploadScreenshotReport.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            log.error("", e);
        }
        Objects.requireNonNull(uploadScreenshotReport);
        this.setUrl(uploadScreenshotReport.getUrl());
        this.setUploadResult(UploadResult.getUploadResultStruct(uploadScreenshotReport.getUploadResult()));
        return this;
    }
}

